package com.maegul.web.components;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.wicketstuff.html5.media.MediaSource;
import org.wicketstuff.html5.media.audio.Html5Audio;

public class AudioPlayer extends Panel {

	private static final long serialVersionUID = 1L;

	public AudioPlayer(String id, List<com.maegul.data.entities.MediaSource> src) {
		super(id);
		final List<MediaSource> mediaSource = new ArrayList<MediaSource>();
		for (com.maegul.data.entities.MediaSource ms : src) {
			mediaSource.add(new MediaSource(ms.getSrc(), ms.getMimeType()));
		}

		IModel<List<MediaSource>> mediaSourceList = new AbstractReadOnlyModel<List<MediaSource>>() {
			private static final long serialVersionUID = 1L;

			public List<MediaSource> getObject() {
				return mediaSource;
			}
		};

		add(new Html5Audio("player", mediaSourceList) {

			private static final long serialVersionUID = 1L;

			@Override
			protected boolean isControls() {
				return true;
			}

			@Override
			protected boolean isAutoPlay() {
				return true;
			}
		});
	}

}
